
#include "qyZipFileFilter.h"
#include "qyFile.h"

//-----------------------------------------------------------------------
qyZipFileFilter::qyZipFileFilter()
{

}

//-----------------------------------------------------------------------
qyZipFileFilter::~qyZipFileFilter()
{

}

//-----------------------------------------------------------------------
bool qyZipFileFilter::LoadFileToMemory( const qyString &strAbsoluteFileName, qyFile &file )
{
	int res = unzLocateFile( m_handle, strAbsoluteFileName.c_str(), 0 );
	if ( res != UNZ_OK )
	{
		return false;
	}
	
	unz_file_info fileInfo;
	res = unzGetCurrentFileInfo( m_handle, &fileInfo, 0, 0, 0, 0, 0, 0 );
	char *buf = ( char * )file.AllockMemChunk( (unsigned long)fileInfo.uncompressed_size );
	buf[fileInfo.uncompressed_size] = '\0';
	int length;
	unzOpenCurrentFile( m_handle );
	length = unzReadCurrentFile( m_handle, buf, fileInfo.uncompressed_size );    
	if ( length != fileInfo.uncompressed_size )
	{
		file.FreeMemChunk();
		return false;
	}
	return true;
	/*
	zzip_file *zipfile = NULL;
	zipfile = zzip_file_open( m_zipDir, strAbsoluteFileName.c_str(), ZZIP_ONLYZIP | ZZIP_CASELESS );
	if ( zipfile == NULL )
		return false;
	char *buf = ( char * )file.AllockMemChunk( (unsigned long)zipfile->usize );
	buf[zipfile->usize] = '\0';
	size_t length;
	length = zzip_file_read( zipfile, buf, zipfile->usize );
	if ( length != zipfile->usize )
	{
		file.FreeMemChunk();
		zzip_file_close( zipfile );
		return false;
	}
	zzip_file_close( zipfile );
	return true;
	*/
}

//-----------------------------------------------------------------------


